package hczc.longcai.com.hccrowdfunding.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;

/**
 * Created by Administrator on 2016/1/25.
 */
public class DBHelper extends SQLiteOpenHelper {

    /**
     * 数据库名
     */
    private static final String DB_NAME = "h_jijin.db";
    /**
     * 数据库版本号
     */
    private static final int VERSION = 1;

    /**
     * 存放地址表字段的内部类
     */
    public static abstract class Address implements BaseColumns {

        //地址表名
        public static final String TABLE_ADDRESS = "address";
        //收货人姓名
        public static final String COLUMN_NAME_NAME = "name";
        //收货人电话
        public static final String COLUMN_NAME_PHONE = "phone";
        //收货人所在地区
        public static final String COLUMN_NAME_AREA = "area";
        //收货人详细地址
        public static final String COLUMN_NAME_ADDRESS = "address";
        //是否为默认地址
        public static final String COLUMN_NAME_DEFAULT = "aDefault";

    }

    /**
     * 存放评论字段的内部类
     */
    public static abstract class Comment implements BaseColumns {
        //评论表名
        public static final String TABLE_COMMENT = "comment";
        //用户头像
        public static final String COLUMN_NAME_USER_HEAD = "head";
        //用户昵称
        public static final String COLUMN_NAME_USER_NICKNAME = "nickname";
        //评论时间
        public static final String COLUMN_NAME_TIME = "time";
        //是否点赞
        public static final String COLUMN_NAME_LIKE = "like";
        //评论内容
        public static final String COLUMN_NAME_CONTENT = "content";
    }

    /**
     * 存放Banner中数据字段的内部类
     */
    public static abstract class Banner implements BaseColumns{
        //Banner表名
        public static final String TABLE_BANNER = "banner";
        //Banner的图片
        public static final String COLUMN_NAME_BANNER_IMG = "img";
        //Banner的链接
        public static final String COLUMN_NAME_BANNER_URL = "url";
    }

    /**
     * 存放资讯中字段的内部类
     */
    public static abstract class Information implements BaseColumns{
        //资讯表名
        public static final String TABLE_INFORMATION = "information";
        //资讯的ID
        public static final String COLUMN_NAME_INFORMATION_ID = "id";
        //资讯的title
        public static final String COLUMN_NAME_INFORMATION_TITLE = "title";
    }

    /**
     * 存放用户信息的数据库
     */
    public static abstract class Minfo implements BaseColumns{
        //用户信息表名
        public static final String TABLE_USERS = "userinfo";
        //用户的uid
        public static final String COLUMN_NAME_USER_ID = "id";
        //用户名
        public static final String COLUMN_NAME_USER_NAME = "name";
        //用户的email
        public static final String COLUMN_NAME_USER_EMAIL = "email";
        //用户的手机号
        public static final String COLUMN_NAME_USER_PHONE = "phone";
        //用户的性别
        public static final String COLUMN_NAME_USER_SEX = "sex";
        //用户的真实姓名
        public static final String COLUMN_NAME_USER_REAL_NAME = "realname";
        //用户的身份证号
        public static final String COLUMN_NAME_USER_IDCARD = "idcard";
        //冻结金额
        public static final String COLUMN_NAME_USER_MONEY_FREEZE = "freeze";
        //募集的钱数
        public static final String COLUMN_NAME_USER_MONEY_COLLECT = "collect";
        //账户可用余额
        public static final String COLUMN_NAME_USER_ACCOUNT_MONEY = "money";
        //用户头像
        public static final String COLUMN_MANE_USER_HEAD = "head";
    }

    /**
     * 存放项目字段的内部类
     */
    public static abstract class Project implements BaseColumns{
        //项目表名
        public static final String TABLE_PROJECT = "project";
        //项目的ID
        public static final String COLUMN_NAME_PROJECT_ID = "id";
        //项目的类型
        public static final String COLUMN_NAME_PROJECT_TYPE = "type";
        //项目的名称
        public static final String COLUMN_NAME_PROJECT_NAME = "name";
        //众筹总额
        public static final String COLUMN_NAME_PROJECT_MONEY = "money";
        //已筹集到
        public static final String COLUMN_NAME_PROJECT_HAS_BORROW = "has_borrow";
        //众筹发布的时间
        public static final String COLUMN_NAME_PROJECT_BORROW_TIMES = "borrow_times";
        //项目的图片
        public static final String COLUMN_NAME_PROJECT_BORROW_IMG = "borrow_img";
        //众筹需要的时间
        public static final String COLUMN_NAME_PROJECT_BORROW_DURATION = "borrow_duration";
        //项目的利率
        public static final String COLUMN_NAME_PROJECT_RATE = "rage";
        //项目进度
        public static final String COLUMN_NAME_PROJECT_PROGRESS = "progress";
        //项目的内容
        public static final String COLUMN_NAME_PROJECT_INFO = "info";
        //项目的状态
        public static final String COLUMN_NAME_PROFECT_STATUS = "status";
    }

    /**
     * 创建项目信息表的SQL语句
     */
    public static final String SQL_CREATE_PROJECT_INFO = "CREATE TABLE " + Project.TABLE_PROJECT +
            "(" + Project._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Project.COLUMN_NAME_PROJECT_ID + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_TYPE + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_NAME + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_MONEY + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_HAS_BORROW + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_BORROW_TIMES + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_BORROW_IMG + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_BORROW_DURATION + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_RATE + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_PROGRESS + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROJECT_INFO + " TEXT NOT NULL," +
            Project.COLUMN_NAME_PROFECT_STATUS + " TEXT NOT NULL)";

    /**
     * 创建用户信息表的SQL语句
     */
    public static final String SQL_CREATE_USER_INFO = "CREATE TABLE " + Minfo.TABLE_USERS +
            "(" + Minfo._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Minfo.COLUMN_NAME_USER_ID + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_NAME + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_EMAIL + " TEXT," +
            Minfo.COLUMN_NAME_USER_PHONE + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_SEX + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_REAL_NAME + " TEXT," +
            Minfo.COLUMN_NAME_USER_IDCARD + " TEXT," +
            Minfo.COLUMN_NAME_USER_MONEY_FREEZE + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_MONEY_COLLECT + " TEXT NOT NULL," +
            Minfo.COLUMN_NAME_USER_ACCOUNT_MONEY + " TEXT NOT NULL," +
            Minfo.COLUMN_MANE_USER_HEAD + " TEXT NOT NULL)";

    /**
     * 创建资讯表的SQL语句
     */
    public static final String SQL_CREATE_INFORMATION = "CREATE TABLE " + Information.TABLE_INFORMATION +
            "(" + Information._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Information.COLUMN_NAME_INFORMATION_ID + " TEXT NOT NULL," +
            Information.COLUMN_NAME_INFORMATION_TITLE + " TEXT)";

    /**
     * 创建Banner表的SQL语句
     */
    private static final String SQL_CREATE_BANNER = "CREATE TABLE " + Banner.TABLE_BANNER +
            "(" + Banner._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Banner.COLUMN_NAME_BANNER_IMG + " TEXT NOT NULL," +
            Banner.COLUMN_NAME_BANNER_URL + " TEXT)";

    /**
     * 创建地址表的SQL语句
     */
    private static final String SQL_CREATE_ADDRESS = "CREATE TABLE " + Address.TABLE_ADDRESS +
            "(" + Address._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Address.COLUMN_NAME_NAME + " TEXT NOT NULL," +
            Address.COLUMN_NAME_PHONE + " TEXT NOT NULL," +
            Address.COLUMN_NAME_AREA + " TEXT NOT NULL," +
            Address.COLUMN_NAME_ADDRESS + " TEXT NOT NULL," +
            Address.COLUMN_NAME_DEFAULT + " INTEGER NOT NULL)";

    /**
     * 创建评论表的SQL语句
     */
    private static final String SQL_CREATE_COMMENT = "CREATE TABLE " + Comment.TABLE_COMMENT +
            "(" + Comment._ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
            Comment.COLUMN_NAME_USER_HEAD + " TEXT NOT NULL," +
            Comment.COLUMN_NAME_USER_NICKNAME + " TEXT NOT NULL," +
            Comment.COLUMN_NAME_TIME + " TEXT NOT NULL," +
            Comment.COLUMN_NAME_LIKE + " INTEGER NOT NULL," +
            Comment.COLUMN_NAME_CONTENT + " TEXT NOT NULL)";


    public DBHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(SQL_CREATE_ADDRESS);
        db.execSQL(SQL_CREATE_COMMENT);
        db.execSQL(SQL_CREATE_BANNER);
        db.execSQL(SQL_CREATE_INFORMATION);
        db.execSQL(SQL_CREATE_PROJECT_INFO);
        db.execSQL(SQL_CREATE_USER_INFO);
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
